package com.itlong.cloud.POJO.VO.app;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <desc>
 *      APP获取访客通行密码记录VO类
 * </desc>
 *
 * @createDate 2017/10/31
 */
@Data
@NoArgsConstructor
public class AppGetVisitorRecordPageVO implements Serializable,Comparable<AppGetVisitorRecordPageVO>{
    private String passId;                  //通行密码记录id
    private String passStatus;                  //通行密码状态
    private String passWord;                    //通行密码
    private String visitorPhoneNo;              //访客手机号，用于分享时发送短信
    private String countLimit;                  //次数限制
    private String startTime;                   //起始时间
    private String endTime;                     //过期时间
    private String qrcode;                      //生成二维码信息
    private String qrCodeUrl;
    private String visitorName;
    private String facePicUrl;
    private String deviceAdress;
    private String address;
    private String isShare;
    private String passNumber;
    private String visitorCause;
    private String visitorTime;
    private String passQrCodeUrl;
    private String plateNumber;
    private String isExpired;                   //是否过期 1未过期 2已过期
    private Integer ownerCheckStatus;           //业主审批状态0未审批 1审批通过2审批拒绝
    private Integer checkStatus;                //物业审批状态0未审批 1审批通过2审批拒绝
    private String roomAddress;                 //访客房间地址
    private String projectId;       //项目id
    private String communityName;   //小区名称
    @Override
    public int compareTo(AppGetVisitorRecordPageVO o) {
        if(Integer.valueOf(this.getPassStatus()) > Integer.valueOf(o.getPassStatus())){
            return 1;
        }
        if(this.getPassStatus().equals(o.getPassStatus())) {
            return 0;
        }
        return -1;
    }

    public String getIsExpired() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (StringUtils.isEmpty(String.valueOf(startTime)) && StringUtils.isEmpty(String.valueOf(endTime))) {
            return "";
        }else{
            try {
                Date startDate = df.parse(startTime);
                Date endDate = df.parse(endTime);
                Date nowDate = df.parse(df.format(new Date()));
                if((nowDate.getTime()>=startDate.getTime()) && (nowDate.getTime()<=endDate.getTime()) ){
                    return "0";
                }else if(nowDate.getTime()<startDate.getTime()){
                    return "0";
                } else{
                    return "1";
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
        return "";
    }
}
